<!--#
layout("/layouts/platform.html"){
#-->
<div id="app" v-cloak>
    <el-table
            :data="tableData"
            size="small"
            header-align="center"
            style="width: 100%"

    >
        <!--昵称-->
        <el-table-column
                label="昵称"
                prop="toUserName"
                header-align="center"
                :show-overflow-tooltip="true"
                align="center">
        </el-table-column>
        <!---->
        <el-table-column
                sortable
                prop="content"
                label="文本"
                header-align="center"
                align="center">
        </el-table-column>
        <!---->
        <el-table-column
                sortable
                label="附件"
                header-align="center"
                align="center">
            <template slot-scope="scope">
                {{imgUrisFormat(scope.row.imgUris)}}

            </template>
        </el-table-column>
        <!--操作下拉菜单-->
        <el-table-column
                label="操作"
                width="120"
                align="center">
            <template slot-scope="scope">
                <el-dropdown @command="dropdownCommand" v-if="scope.row.state==0">
                    <el-button size="mini">
                        <i class="ti-settings"></i>
                        <span class="ti-angle-down"></span>
                    </el-button>
                    <el-dropdown-menu slot="dropdown">
                        <el-dropdown-item
                                :command="{flag:true,id:scope.row.id,userId:scope.row.toUserId}">
                            禁言
                        </el-dropdown-item>
                        <el-dropdown-item
                                :command="{flag:false,id:scope.row.id}">
                            无效
                        </el-dropdown-item>
                    </el-dropdown-menu>
                </el-dropdown>
            </template>
        </el-table-column>
    </el-table>
    <!--分页容器-->
    <el-row class="el-pagination-container">
        <el-pagination
                @size-change="pageSizeChange"
                @current-change="pageNumberChange"
                :current-page="pageForm.pageNumber"
                :page-sizes="[10, 20, 30, 50]"
                :page-size="pageForm.pageSize"
                layout="total, sizes, prev, pager, next, jumper"
                :total="pageForm.totalCount">
        </el-pagination>
    </el-row>

</div>
<script>
    new Vue({
        el: "#app",
        data: function () {
            var self = this;
            return {
                options: [{
                    value: '',
                    label: '全部类型'
                }, {
                    value: 1,
                    label: '主播'
                }, {
                    value: 0,
                    label: '用户'
                }],
                pickerOptions: {
                    disabledDate: function (time) {
                        return time.getTime() > new Date(new Date(new Date().toLocaleDateString()).getTime() + 24 * 60 * 60 * 1000);
                    },
                    shortcuts: [{
                        text: '最近一周',
                        onClick: function (picker) {
                            var end = new Date();
                            var start = new Date();
                            var temp = moment().add(-1, 'weeks').valueOf();
                            start.setTime(temp);
                            picker.$emit('pick', [start, end]);
                        }
                    }, {
                        text: '最近一个月',
                        onClick: function (picker) {
                            var end = new Date();
                            var start = new Date();
                            var temp = moment().add(-1, 'months').valueOf();
                            start.setTime(temp);
                            picker.$emit('pick', [start, end]);
                        }
                    }, {
                        text: '最近三个月',
                        onClick: function (picker) {
                            var end = new Date();
                            var start = new Date();
                            var temp = moment().add(-3, 'months').valueOf();
                            start.setTime(temp);
                            picker.$emit('pick', [start, end]);
                        }
                    }]
                },
                searchDate: [],
                addDialogVisible: false,
                editDialogVisible: false,
                titlePopu: 0,
                tableData: [],
                pageForm: {
                    pageNumber: 1,
                    pageSize: 10,
                    totalCount: 0,
                    userType: "",
                    searchKeyword: "",
                    searchDate: "",
                },
                formData: {
                    nickname: "",
                    email: "",
                    anchor: "",
                    disabled: false,
                },
                formRules: {
                    // 新增User昵称必须填写。修改User暂时没有修改昵称功能。
                    nickName: [
                        {required: true, message: '请输入昵称', trigger: 'blur'}
                    ],
                    email: [
                        {required: true, message: '请输入邮箱！', trigger: 'blur'}
                    ],
                    anchor: [
                        {required: true, message: '请选择User类型', trigger: 'change'}
                    ]
                }
            }
        },
        methods: {
            pageNumberChange: function (val) {//页码更新操作
                this.pageForm.pageNumber = val;
                this.pageData();
            },
            pageSizeChange: function (val) {//分页大小更新操作
                this.pageForm.pageSize = val;
                this.pageData();
            },
            pageData: function () {//加载分页数据
                var self = this;
                sublime.showLoadingbar();//显示loading
                if (self.searchDate) {
                    self.pageForm.searchDate = self.searchDate.toString();
                } else {
                    self.pageForm.searchDate = "";
                }
                $.post(base + "/platform/user/chat/report/data", self.pageForm, function (data) {
                    sublime.closeLoadingbar();//关闭loading
                    if (data.code == 0) {
                        self.tableData = data.data.list;
                        self.pageForm.totalCount = data.data.totalCount;
                    } else {
                        self.$message({
                            message: data.msg,
                            type: 'error'
                        });
                    }
                }, "json");
            },
            doSearch: function () {
                this.pageForm.pageNumber = 1;
                this.pageData();
            },
            openAdd: function () {// 新建/修改User按钮逻辑
                var self = this;
                self.titlePopu = 0;
                this.editDialogVisible = true;
                //打开新增窗口,表单先清空
                this.formData = {
                    anchor: false
                };
                if (this.$refs["editForm"]) {
                    this.$refs["editForm"].resetFields();
                }
            },
            doEdit: function () { // 提交新增/修改
                var self = this;
                self.$refs["editForm"].validate(function (valid) {
                    if (valid) {
                        //titlePopu=0是新增,1是修改
                        if (self.titlePopu == 0) {
                            $.post(base + "/platform/user/manager/add", self.formData, function (data) {
                                if (data.code == 0) {
                                    self.$message({
                                        message: data.msg,
                                        type: 'success'
                                    });
                                    self.doSearch();
                                    self.editDialogVisible = false;
                                } else {
                                    self.$message({
                                        message: data.msg,
                                        type: 'error'
                                    });
                                }
                            }, "json");
                        } else {
                            $.post(base + "/platform/user/manager/editDo", self.formData, function (data) {
                                if (data.code == 0) {
                                    self.$message({
                                        message: data.msg,
                                        type: 'success'
                                    });
                                    self.doSearch();
                                    self.editDialogVisible = false;
                                } else {
                                    self.$message({
                                        message: data.msg,
                                        type: 'error'
                                    });
                                }
                            }, "json");
                        }
                    }
                });
            },
            sessionDisable: function (row) {
                let _self = this;
                $.post(base + "/platform/user/manage/session", {disabled: row.sessionDisabled}, function (data) {
                    _self.pageData()
                }, "json");
            },
            setManager: function (row) {
                let _self = this;
                $.post(base + "/platform/user/manage", {flag: row.roomManager}, function (data) {
                    _self.pageData()
                }, "json");
            },
            imgUrisFormat:function(uris){
                return uris.split(",").map((value, index, array)=>{
                    return "<a href='"+value+"' target='_blank'><img src='"+value+"'  /></a> "
                }).join("")
            },
            dropdownCommand: function (command) {//监听下拉框事件
                let self = this;
                $.post(base + "/platform/user/chat/report/do" , command, function (data) {
                        self.pageData();
                    }, "json");
            },
        },
        created: function () {
            this.pageData();
        }
    });
</script>

<!--#
}
#-->